package info.xmlprint.action.exp;

import info.xmlprint.core.project.PrintProject;
import info.xmlprint.run.RuntimeUtil;
import info.xmlprint.util.FileUtil;

import org.eclipse.core.resources.IProject;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;

public class ExportXmlp extends BasicNewResourceWizard {
	private BasicExportPage mainPage;

	public void addPages() {
		super.addPages();
		mainPage = new BasicExportPage(getSelection());
		mainPage.setDescription("Please enter a destination xmlp file.");
		mainPage.setTitle("Xmlp File");
		mainPage.setExportDialogTitle("Export to Xmlp File");
		mainPage.setFilterExtension(new String[] { "*.xmlp", "*.*" });//$NON-NLS-1$
		addPage(mainPage);
	}

	public boolean performFinish() {
		if (!mainPage.validExportFile()) {
			return false;
		}
		String output = mainPage.getExportPath();

		PrintProject print = RuntimeUtil.getInstance().getCurrentPrintProject();
		if (print == null) {
			return false;
		}

		IProject project = print.getProject();

		String input = project.getLocationURI().getPath();
		if (FileUtil.write2zip(input, output))
			return true;

		return false;

	}

}